package serviceImpl;


import javax.persistence.Query;

import model.Usuario;
import service.UsuarioService;

public class UsuarioServiceImpl extends GenericServiceImpl<Usuario> implements UsuarioService {
	/**
	 * 
	 */
	private static final long serialVersionUID = -246437020768778940L;
	private Query query;

	public boolean procuraEmail(String email) {
		query = getEm()
				.createQuery("Select c from Usuario c where c.email = :email");
		query.setParameter("email", email);
		if (query.getResultList().size() == 1) {
			return true;
		}
		return false;
	}

	public boolean autentica(String email, String senha) {
		query = getEm()
				.createQuery("Select c from Usuario c where c.senha = :senha and c.email = :email");
		query.setParameter("senha", senha);
		query.setParameter("email", email);
		if (query.getResultList().size() == 1) {
			return true;
		}
		return false;
	}

	public Usuario procuraUnicoUsuario(String email, String senha) {
		query = getEm().createQuery("Select c from Usuario c where c.senha = :senha and c.email = :email");
		query.setParameter("senha", senha);
		query.setParameter("email", email);
		if (query.getResultList().size() == 1) {
			return (Usuario) query.getResultList().get(0);
	}
		return null;
	}

}
